﻿using System;
using System.Runtime.CompilerServices;
using UnityEngine;

public class FadeChildRenderersOnEnable : MonoBehaviour
{
    public float duration = 0.5f;
    public float endValue = 0.2f;
    public Action onFinished;
    public float startValue = 1f;

    private void AsTransparent(Material material)
    {
        material.SetFloat("_Mode", 2f);
        material.SetInt("_SrcBlend", 5);
        material.SetInt("_DstBlend", 10);
        material.SetInt("_ZWrite", 0);
        material.DisableKeyword("_ALPHATEST_ON");
        material.EnableKeyword("_ALPHABLEND_ON");
        material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
        material.renderQueue = 0xbb8;
    }

    private void OnEnable()
    {
        Renderer[] componentsInChildren = base.GetComponentsInChildren<Renderer>();
        for (int i = 0; i < componentsInChildren.Length; i++)
        {
            <OnEnable>c__AnonStorey78 storey = new <OnEnable>c__AnonStorey78 {
                <>f__this = this,
                ren = componentsInChildren[i]
            };
            this.AsTransparent(storey.ren.material);
            this.StartAnimateFloat(this.startValue, this.endValue, this.duration, new Action<float>(storey.<>m__13F), new Action(storey.<>m__140));
        }
    }

    [CompilerGenerated]
    private sealed class <OnEnable>c__AnonStorey78
    {
        internal FadeChildRenderersOnEnable <>f__this;
        internal Renderer ren;

        internal void <>m__13F(float a)
        {
            this.ren.material.color = this.ren.material.color.SetA(a);
        }

        internal void <>m__140()
        {
            if (this.<>f__this.onFinished != null)
            {
                this.<>f__this.onFinished();
            }
        }
    }
}

